<style>
    .order-header {
        font-size: small;color: grey;padding-left: 2%
    }
    .order-header-text {
        padding-left: 5px
    }
</style>
@foreach($data as $pSkuId => $_data)
    <div id="sku_{{ $pSkuId }}" class="box box-primary">
        <div class="box-header with-border" style="background-color: #f1f9fd">
            <input type="checkbox" class="grid-row-checkbox" data-id="{{ $pSkuId }}" />
            <input type="hidden" id="psku_code_{{ $pSkuId }}" value="{{ $_data['psku_code'] }}"/>
            <input type="hidden" id="apply_detail_total_{{ $pSkuId }}" value="{{ $_data['apply_detail_num'] }}"/>
            <input type="hidden" id="planned_num_total_{{ $pSkuId }}" value="{{ $_data['plan_num'] }}"/>
            <select class="supplier" id="supplier_id_{{ $pSkuId }}">
                {{ getOptions(\App\Models\Product\ProductSupplier::getSupplierOptionBySku($pSkuId),$_data['supplier_id'],false) }}
            </select>
            <span class="order-header">SKU</span><span class="order-header-text">{{ $_data['psku_code'] }}&nbsp;&nbsp;{{ $_data['psku_cn'] }}</span>
            <span class="order-header">备货数量</span><span class="order-header-text">{{ $_data['apply_detail_num'] }}</span>
            <span class="order-header">已计划数量</span><span class="order-header-text">{{ $_data['plan_num'] }}</span>
            <span class="order-header">本次计划采购</span>
            <span class="order-header-text">
<input type="text" class="this_plan_num_"
       style="width: 100px; text-align: right;"
       id="this_plan_num_{{ $pSkuId }}"
       data-value="{{ max(0,($_data['apply_detail_num'] - $_data['plan_num'])) }}"
       value="{{ max(0,($_data['apply_detail_num'] - $_data['plan_num'])) }}">
            </span>
        </div>
        <div class="box-body table-responsive no-padding">
            <table class="table table-hover">
                <thead>
                <tr>
                    <th>备货单号</th>
                    <th>站点</th>
                    <th>备货数量</th>
                    <th>已计划采购</th>
                    <th>创建时间</th>
                </tr>
                </thead>
                <tbody>
                @foreach($_data['detail'] as $applyDetailId => $item)
                    <tr>
                        <td>
                            <input type="hidden" class="apply-detail" value="{{ $applyDetailId.'_'.$item['apply_detail_num'].'_'.$item['plan_num'] }}"/>
                            {{ $item['stocking_no'] }}
                        </td>
                        <td>{{ $item['area'] }}</td>
                        <td>{{ $item['apply_detail_num'] }}</td>
                        <td>{{ $item['plan_num']  }}</td>
                        <td>{{ $item['created_at']  }}</td>
                    </tr>
                @endforeach
                </tbody>
            </table>
        </div>
    </div>
@endforeach
<script language="JavaScript" type="text/javascript">
    $(function () {
        $(".this_plan_num_").inputmask("integer",
            {
                onKeyValidation: function () {
                    var v = $(this).data('value');
                    if($(this).val() <= 0){
                        $(this).val(v);
                    }
                }
            }
        );
        $(".supplier").select2({"allowClear":true, "placeholder":"请选择供应商","width": "auto"});
        $('.grid-row-checkbox').iCheck({checkboxClass:'icheckbox_minimal-blue'}).on('ifChanged', function () {
            if (this.checked) {
                $(this).closest('tr').css('background-color', '#ffffd5');
            } else {
                $(this).closest('tr').css('background-color', '');
            }
        });
    });
</script>
